{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b45b37ad",
   "metadata": {},
   "source": [
    "# 元组(tuple)\n",
    "> [元组](https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences)\n",
    "\n",
    "- 它是几乎和list完全一样的序列数据\n",
    "- 不同之处在于，元组一旦创建好就**不能改变**\n",
    "- 元组形式：用括号(1,2,3) \n",
    "- 元组方法：\n",
    "  - count()\n",
    "  - index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "22dae0a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=10, tm_mday=25, tm_hour=11, tm_min=30, tm_sec=55, tm_wday=0, tm_yday=298, tm_isdst=0)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7292dd4f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('apple', 'banana')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "fruits = \"apple\", \"banana\", \"apple\"\n",
    "print(fruits)\n",
    "print(type(fruits))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2b151d60",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fruits.count(\"apple\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8aba343f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fruits.index(\"banana\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e406482a",
   "metadata": {},
   "source": [
    "# 字典(dictionary)\n",
    "> [字典](https://docs.python.org/3/tutorial/datastructures.html#dictionaries)\n",
    "\n",
    "- 字典的创建方式\n",
    "  - 直接创建字典，按照字典的结构 dict = {key1: value1, key2: value2,  ...}\n",
    "  - dict()创建字典 dict(key1 = value1, key2 = value2, ...)\n",
    "  - 创建空字典，通过添加值的方法创建字典\n",
    "- 字典的一些性质\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3397f84e",
   "metadata": {},
   "source": [
    "## 字典的创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0ca18646",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'001': 'ahu', '002': 'peiqi', '003': 'qiaozhi'}\n",
      "{'name': 'ahu', 'sex': 'woman', 'age': 20, 'job': 'student'}\n"
     ]
    }
   ],
   "source": [
    "# 第一种方法\n",
    "info = {\n",
    "    \"001\": \"ahu\",\n",
    "    \"002\": \"peiqi\",\n",
    "    \"003\": \"qiaozhi\"\n",
    "}\n",
    "\n",
    "info_ahu = {\n",
    "    \"name\": \"ahu\",\n",
    "    \"sex\": \"woman\",\n",
    "    \"age\": 20,\n",
    "    \"job\": \"student\"\n",
    "}\n",
    "\n",
    "print(info)\n",
    "print(info_ahu)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ad44d554",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'peiqi', 'sex': 'man', 'age': 21, 'job': '海王'}\n"
     ]
    }
   ],
   "source": [
    "# 第二种方法\n",
    "info_peiqi = dict(\n",
    "    name = \"peiqi\",\n",
    "    sex =  \"man\",\n",
    "    age =  21,\n",
    "    job = \"海王\"\n",
    ")\n",
    "print(info_peiqi)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e946aca9",
   "metadata": {},
   "source": [
    "### 第一种和第二种方法的区别\n",
    "\n",
    "1. dict() vs dict{}\n",
    "2. name vs \"name\"\n",
    "3. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "db12a0fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'qiaozhi', 'sex': 'man', 'age': 25, 'job': 'student'}\n"
     ]
    }
   ],
   "source": [
    "# 第三种方法\n",
    "\n",
    "info_qiaozhi = {}\n",
    "\n",
    "info_qiaozhi[\"name\"] = \"qiaozhi\"\n",
    "info_qiaozhi[\"sex\"] = \"man\"\n",
    "info_qiaozhi[\"age\"] = 25\n",
    "info_qiaozhi[\"job\"] = \"student\"\n",
    "\n",
    "print(info_qiaozhi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e35fac07",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
